package com.whq.security.context;

import org.springframework.util.Assert;

public class GlobalDataContextHolderStrategy implements DataContextHolderStrategy {

    private static Object contextHolder;

    @Override
    public void clearContext() {
        contextHolder = null;
    }

    @Override
    public Object getContext() {
        if (contextHolder == null) {
            contextHolder = createEmptyContext();
        }
        return contextHolder;
    }

    @Override
    public void setContext(Object context) {
        Assert.notNull(context, "Only non-null context instances are permitted");
        contextHolder = context;
    }

    @Override
    public Object createEmptyContext() {
        return new Object();
    }
}
